#include <windows.h>
#include <tchar.h>


static TCHAR className[] = _T("BlocksMainWindow");
static TCHAR windowTitle[] = _T("Blocks!");


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow);


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{

	WNDCLASS wc = {};

	wc.lpfnWndProc = WindowProc;
	wc.hInstance = hInstance;
	wc.lpszClassName = className;

	RegisterClass(&wc);

	HWND hwnd = CreateWindowEx(
		0,								//optional styles
		className,						//class
		windowTitle,					//text
		WS_OVERLAPPEDWINDOW,			//style
		CW_USEDEFAULT, CW_USEDEFAULT,	//size
		CW_USEDEFAULT, CW_USEDEFAULT,	//position
		NULL,							//parent
		NULL,							//menu
		hInstance,						//instance handle
		NULL							//additional app data
		);

	if(!hwnd) return 0;
	
	ShowWindow(hwnd, nCmdShow);

	MSG msg = {};

	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return 0;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
		case WM_DESTROY:
			{
				PostQuitMessage(0);
			}
			return 0;
		case WM_PAINT:
			{
				PAINTSTRUCT ps;
				HDC hdc = BeginPaint(hwnd, &ps);
				FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
				EndPaint(hwnd, &ps);
			}
			return 0;
	}
	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}